package horde.patterns.master;

import horde.internalResources.HorrorControl.HorrorControl;
import horde.internalResources.dictionaries.dictionary;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

/**
 * @author Andres Picazo
 */
public class MasterPanel extends JFrame implements ActionListener {

    private int size = 0;
    private JPanel canvas;
    private MenuItem small, big;

    public MasterPanel() {
        super();
        try {
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (Exception e) {
        }
        setTitle(dictionary.getString("master.tray.controlPanel.name"));
        small();
        canvas = new JPanel(new BorderLayout(2, 2));
        canvas.setBorder(BorderFactory.createLineBorder(Color.black));
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        add(canvas);
        testPanels();
        setVisible(false);
    }

    private void testPanels() {
        canvas.add(HorrorControl.getFrameInstance().getContentPane(), BorderLayout.CENTER);
    }

    public void showPanel() {
        setVisible(true);
    }

    public void hidePanel() {
        setVisible(false);
    }

    public void swapVisibility() {
        setVisible(!isVisible());
    }

    public void small() {
//        this.setUndecorated(true);
        size = 0;
        this.setVisible(false);
        dispose();
        if (!this.isUndecorated()) {
            this.setUndecorated(true);
        }
        setSize(new Dimension(600, 360));
        Dimension screenSize = getToolkit().getScreenSize();
        this.setLocation(screenSize.width - 600, screenSize.height - 400);
//        this.setVisible(true);
    }

    public void big() {
        size = 1;
        this.setVisible(false);
        dispose();
        if (this.isUndecorated()) {
            this.setUndecorated(false);
        }
        setSize(new Dimension(500, 500));
        setLocationRelativeTo(null);
//        this.setVisible(true);
    }

    public void swapSize() {
        if (size == 0) {
            big();
        } else {
            small();
        }
        this.setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == big) {
            big();
        } else if (e.getSource() == small) {
            small();
        }
    }
}
